package com.bjyhl.app;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.bjyhl.core.app.Latte;

public class AppManager {
    private static AppManager instance;
    /**     * 单一实例     */
    public static AppManager getAppManager() {
        if (instance == null) {
            instance = new AppManager();
        }
        return instance;
    }

    /**     * 退出应用程序     */
    public void AppExit() {
        try {
//            Intent intent = new Intent(YLTApplication.getContext(), MainActivity.class);
//            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
//                    Intent.FLAG_ACTIVITY_NEW_TASK);
//            YLTApplication.getContext().startActivity(intent);
//            finishAllActivity();
//            退出程序

//重启程序
            Intent intent = new Intent(Latte.getApplicationContext(),
                    MainActivity.class);
            PendingIntent restartIntent = PendingIntent.getActivity(
                    Latte.getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

            AlarmManager mgr = (AlarmManager) Latte.getApplicationContext()
                    .getSystemService(Context.ALARM_SERVICE);
            mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000,
                    restartIntent); // 2秒钟后重启应用
            android.os.Process.killProcess(android.os.Process.myPid());
        } catch (Exception e) {

        }
    }
}
